package com.yoomiito.app.ui.songduoduo.freegoods

import androidx.cardview.widget.CardView
import androidx.recyclerview.widget.RecyclerView
import android.text.SpannableString
import android.view.ViewGroup
import android.widget.ImageView
import android.widget.TextView
import com.chad.library.adapter.base.BaseQuickAdapter
import com.chad.library.adapter.base.BaseViewHolder
import com.yoomiito.app.R
import com.yoomiito.app.model.sdd.SddGoodsInfo
import com.yoomiito.app.utils.*

class ListGoodsAdapter(data:List<SddGoodsInfo>?) :BaseQuickAdapter<SddGoodsInfo,BaseViewHolder>(R.layout.item_goods_10,data){

    override fun convert(helper: BaseViewHolder?, item: SddGoodsInfo?) {
        val view = helper?.getView<androidx.cardview.widget.CardView>(R.id.item_goods_cardView)
        val lp = view?.layoutParams as androidx.recyclerview.widget.RecyclerView.LayoutParams
//        lp.width = ViewGroup.LayoutParams.MATCH_PARENT
        val v0 = DensityUtil.dp2px(0f)
        val v1 = DensityUtil.dp2px(4.5f)
        val v2= DensityUtil.dp2px(12f)
        lp.bottomMargin = DensityUtil.dp2px(9f)
        when{//因为设置了header  所以position从1开始
            helper?.layoutPosition?.rem(2)==0->{
                lp.leftMargin = v1
            }
            else->{
                lp.leftMargin = v2
                lp.rightMargin = v1
            }
        }
        helper?.getView<ImageView>(R.id.item_goods_img).let {
            ImageLoader.getInstance().into(mContext,item?.productImg,it)
        }
        helper?.setText(R.id.goodsTitle,item?.productName)
//        helper?.setGone(R.id.ll2,false)
        helper?.getView<TextView>(R.id.moneyFlag).let { it?.setTextColor(ResUtil.getColor(R.color.color_FF035B)) }
        helper?.getView<TextView>(R.id.goodsPrice).let {
            it?.setTextColor(ResUtil.getColor(R.color.color_FF035B))
            it?.text = "0"
        }
        helper?.getView<TextView>(R.id.oldPrice).let {
            it.text = SpannableUtils.getSpannable("¥${SpannableUtils.handlePrice(item?.marketPrice)}",0)
            it.setTextColor(ResUtil.getColor(R.color.color_balk_999999))
        }
        helper?.setText(R.id.sellSize,"已领 ${item?.volume}")

    }

}